package com.splant.android.smart.UILevel.Community;

import android.content.Context;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.splant.android.R;
import com.splant.android.smart.ModelLevel.WaterListBean;
import com.splant.android.smart.SystemDefinedLevel.LRecyclerview.base.BaseMultiAdapter;
import com.splant.android.smart.SystemDefinedLevel.LRecyclerview.base.SuperViewHolder;
import com.splant.android.smart.UILevel.Utils.sPlantUitl;

public class Garden_WaterList_Select_Adapter extends BaseMultiAdapter<WaterListBean.Water> {

    public Garden_WaterList_Select_Adapter(Context context) {
        super(context);
        addItemType(0,R.layout.garden_waterlist_select_item);
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, final int position) {

        ImageView img_water=holder.getView(R.id.img_water);
        TextView tv_waterName=holder.getView(R.id.tv_waterName);

        FrameLayout fl_switch0=holder.getView(R.id.fl_switch0);
        FrameLayout fl_switch1=holder.getView(R.id.fl_switch1);
        FrameLayout fl_switch2=holder.getView(R.id.fl_switch2);

        CheckBox chk_switch0=holder.getView(R.id.chk_switch0);
        CheckBox chk_switch1=holder.getView(R.id.chk_switch1);
        CheckBox chk_switch2=holder.getView(R.id.chk_switch2);


        final   WaterListBean.Water water=getDataList().get(position);
        int proType= sPlantUitl.getWaterType(water.getWaterId());
        tv_waterName.setText(water.getWaterName());

        if (proType==1)
        {
            fl_switch0.setVisibility(View.VISIBLE);
            fl_switch1.setVisibility(View.INVISIBLE);
            fl_switch2.setVisibility(View.INVISIBLE);
            img_water.setImageResource(R.mipmap.garden_ic_water1_online);
        }
        else if (proType==2)
        {
            fl_switch0.setVisibility(View.VISIBLE);
            fl_switch1.setVisibility(View.VISIBLE);
            fl_switch2.setVisibility(View.INVISIBLE);
            img_water.setImageResource(R.mipmap.garden_ic_water2_online);
        }
        else
        {
            fl_switch0.setVisibility(View.VISIBLE);
            fl_switch1.setVisibility(View.VISIBLE);
            fl_switch2.setVisibility(View.VISIBLE);
            img_water.setImageResource(R.mipmap.garden_ic_water3_online);
        }


        chk_switch0.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked)
                {
                    if (water.getSelectedSwitchs().contains("1")==false)
                    {
                        water.setSelectedSwitchs(water.getSelectedSwitchs()+"1");
                    }
                    else
                    {
                        String s0=water.getSelectedSwitchs().replace("1","");
                        water.setSelectedSwitchs(s0);
                    }
                }
                else
                {
                    if (water.getSelectedSwitchs().contains("1"))
                    {
                        String s0=water.getSelectedSwitchs().replace("1","");
                        water.setSelectedSwitchs(s0);
                    }
                }
            }
        });
        chk_switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                if (isChecked)
                {
                    if (water.getSelectedSwitchs().equals("2")==false)
                    {
                        water.setSelectedSwitchs(water.getSelectedSwitchs()+"2");
                    }
                    else
                    {
                        String s0=water.getSelectedSwitchs().replace("2","");
                        water.setSelectedSwitchs(s0);
                    }
                }
                else
                {
                    if (water.getSelectedSwitchs().contains("2"))
                    {
                        String s0=water.getSelectedSwitchs().replace("2","");
                        water.setSelectedSwitchs(s0);
                    }
                }

            }
        });
        chk_switch2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked)
                {
                    if (water.getSelectedSwitchs().equals("3")==false)
                    {
                        water.setSelectedSwitchs(water.getSelectedSwitchs()+"3");
                    }
                    else
                    {
                        String s0=water.getSelectedSwitchs().replace("3","");
                        water.setSelectedSwitchs(s0);
                    }
                }
                else
                {
                    if (water.getSelectedSwitchs().contains("3"))
                    {
                        String s0=water.getSelectedSwitchs().replace("3","");
                        water.setSelectedSwitchs(s0);
                    }
                }
            }
        });

    }

    private onItemClickListener mListener = null;

    public void setOnItemClickListener(onItemClickListener mListener)
    {
        this.mListener=mListener;
    }

    public interface onItemClickListener {
        void onItemChick(int pos);
    }

}
